#测试函数的定义和调用

#-----------------------------------
# def printMax(a,b):
#     '''比较两个数的大小，输出较大值'''
#     if a>b:
#         print(a,"较大值")
#     else:
#         print(b,"较大值")
#
# printMax(10,44)
# help(printMax.__doc__)
#------------------------------------




#------------------------------------
#返回值
# def my_avg(a,b):
#     '''求两个数的平均值'''
#     return (a+b)/2
#
# c=my_avg(10,50)
# print(c)
# help(my_avg.__doc__)
#---------------------------------




#-----------------------
# def text01(a,b,c):
#     return [a*10,b*20,c*12]
# print(text01(10,15,40))
#---------------------------




#----------------------------
#测试函数也是对象

# def text01():
#     print('sdfafadg')
# text01()
# c=text01()
# c()
#-----------------------------

#测试局部变量，全局变量的效率

# import math
# import time
#
# def test01():
#     start=time.time()
#     for i in range(10000000):
#         math.sqrt(30)
#     end = time.time()
#     print("耗时{0}".format(end-start))
# test01()
# def test02():
#     b=math.sqrt
#     start = time.time()
#     for i in range(10000000):
#         b(30)
#     end = time.time()
#     print("耗时{0}".format(end - start))
# test02()
#---------------------------------------
#测试深拷贝，浅拷贝

# import copy
# a=[10,20,[2,3]]
# b=copy.copy(a)
# print("a:",a)
# print("b:",b)
#
# b.append(30)
# b[2].append(7)
# print("a:",a)
# print("b:",b)
# print()
#
# def DeepCopy():
#     a=[10,20,[2,3]]
#     b=copy.deepcopy(a)
#     print("a:",a)
#     print("b:",b)
#
#     b.append(30)
#     b[2].append(7)
#     print("a:",a)
#     print("b:",b)
# DeepCopy()
#--------------------------------------

# def f1(a,b,c=10,d=20):
#     print(a,b,c,d)
# f1(8,9)
# f1(8,9,19)
# f1(8,9,15,28)
#
# def f1(a,b,c,d):
#     print(a,b,c,d)
# f1(c=10,a=5,b=15,d=60)
#------------------------------------


#测试可变参数（元组，字典）
#---------------------------------------
# def f1(a,b,*c):                        #*c 元组
#     print(a,b,c)
# f1(9,2,2323,234234,234,234,)
#
#
# def f2(a,b,**c):                       #**c 字典
#     print(a,b,c)
# f2(8,34,name="zhangmao",age=27)
#
# def f3(a,b,*c,**d):
#     print(a,b,c,d)
# f3(213,34,234,234,234,234,name="zhangmao",age=27)


#强制命名参数-----------------------------------------------
# def f1(*a,b,c):      #*a是可变参数，将后面的全都收走，造成bc没有赋值
#     print(a,b,c)
# f1(23,234,234,234,b=323,c=23)
#执行结果(23, 234, 234, 234) 323 23



#lambda -----------------------------------------
# f=lambda a,b,c:a+b+c
# print(f)
# print(f(2,4,6))
#
# def i(a,b,c):
#     return(a+b+c)
# print(i(2,4,6))
#
# g=[lambda a:a*3,lambda b:b+5,lambda c:c/2]
# print(g[0](5),g[1](3),g[2](2))
#
# def i(a,b,c):
#     return(a*3,b+5,c/2)
# print(i(5,3,2))

#-----------------------------
# eval("print('abcde')")
# a=10
# b=20
# c=eval("a+b")
# print(c)
#
# dict1=dict(a=100,b=200)
# d=eval("a+b",dict1)
# print(d)
# d=eval("a+b")
# print(d)
#====================================

#测试递归函数基本原理
# def test01(n):
#     print("test01:",n)
#     if n==0:
#         print("over")
#     else:
#         test01(n-1)
#     print("test01:**",n)
# def test02():
#     print("test02")
#
# test01(5)
#----------------------
# def jiechen(n):
#     if n==1:
#         return 1
#     else:
#         return n*jiechen(n-1)
# for i in range(1,6):
#     print(i,'!=',jiechen(i))

#分形树
# import turtle
# def bintree(size):
#   angle = 60    # 分叉的角度
#   if size > 5:    # 长度退出条件
#       turtle.forward(size)
#       turtle.left(angle)
#       bintree(size / 1.6)
#       turtle.right(angle*2)
#       bintree(size / 1.6)
#       turtle.left(angle)
#       turtle.backward(size)
# def main():
#   turtle.speed(0)
#   turtle.hideturtle()
#   turtle.penup()
#   turtle.left(90)
#   turtle.backward(100)
#   turtle.showturtle()
#   turtle.pendown()
#   turtle.pensize(2)
#   turtle.color('green')
#   bintree(150)
#   turtle.done()
# if __name__ == '__main__':
#
#   main()



#----------------------------------------
# from turtle import *
# def Square(self,length):
#   for _ in range(5):
#       self.forward(length)
#       self.right(90)
# def Triangle(self,length):
#   self.left(45)
#   self.forward(length/2**0.5)
#   self.right(90)
#   self.forward(length/2**0.5)
#   self.right(135)
#   self.forward(length)
# def Move2Right(self,length):
#   self.back(length)
#   self.right(45)
#   self.forward(length/2**0.5)
#   self.right(90)
# def Recursive(n, tracer, length):
#   if n<1: return
#   tracers = []
#   for left in tracer:
#       if n<3: left.pencolor('green')
#       else: left.pencolor('brown')
#       Square(left, length)
#       Triangle(left, length)
#       right = left.clone()
#       left.right(45)
#       Move2Right(right, length)
#       tracers.append(left)
#       tracers.append(right)
#   Recursive(n-1, tracers, length/2**0.5)
# def Setup(self, length, speed):
#   self.hideturtle()
#   self.speed(speed)
#   self.penup()
#   self.goto(-length*0.5, -length*1.8)
#   self.seth(90)
#   self.pensize(2)
#   self.pendown()
# def main(level, length, speed=-1):
#   setup(800,600)
#   title('Fractal Tree')
#   if speed==-1: tracer(0)
#   else: tracer(1)
#   t = Turtle()
#   Setup(t, length, speed)
#   from time import sleep
#   sleep(2)
#   Recursive(level, list([t]), length)
#   done()
#   bye()
# if __name__ == '__main__':
#   main(6,150,10)


#测试嵌套函数
# def outer():
#     print("haha")
#
#     def inner():
#         print("hehe")
#     inner()
# outer()



